package ninethwork.three;

import java.util.*;

/**
 * @author ：chenzikang
 * @date ： 2020/4/14
 */


/**
 * 英语翻译中文
 */
public class Translate {

    public static void etoC(Map<String, String> map, String english) {

        System.out.println(map.get(english));

    }


    /**
     * 通过value查找key的方法
     */
    public static Object getKey(Map map, Object value) {
        List<Object> keyList = new ArrayList<>();
        for (Object key : map.keySet()) {
            if (map.get(key).equals(value)) {
                keyList.add(key);
            }
        }
        return keyList;
    }

    /**
     * 中文翻译英语
     */
    public static void ctoE(Map<String, String> map, String Chinese) {

        System.out.println(getKey(map, Chinese));

    }

    /**
     * 插入映射关系
     */
    public static void insert(Map<String, String> map, String english, String chinese) {

        map.put(english, chinese);


    }


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<String, String> map = new HashMap<>();

        map.put("born", "出生");


        System.out.println("请输入调用的功能");
        System.out.println("1、添加单词");
        System.out.println("2、英语查找汉语");
        System.out.println("3、汉语查找英语");

        int temp = scanner.nextInt();

        switch (temp) {

            case 1: {
                String english = scanner.next();
                String chinese = scanner.next();
                insert(map, english, chinese);
                break;
            }

            case 2: {
                System.out.println("请输入要查找的英语");
                String things = scanner.next();
                etoC(map, things);
                break;


            }

            case 3: {
                System.out.println("请输入要查找的汉语");
                String things = scanner.next();
                ctoE(map, things);
                break;
            }


        }


        //


    }
}
